using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;

namespace FireStarterModeller.Logic
{
//    public class ProjectPersistor: IPersistor
//    {
//        private readonly IBoPersistor _boPersistor;
//
//        public ProjectPersistor(IBoPersistor boPersistor)
//        {
//            _boPersistor = boPersistor;
//        }
//
//        public void AddProject(DMSolution dmSolution)
//        {
//            _boPersistor.AddBusinessObject(dmSolution);
//            foreach (DMAssembly projectAssemblyInfo in dmSolution.Assemblies)
//            {
//                _boPersistor.AddBusinessObject(projectAssemblyInfo);
//            }
//            foreach (DMPropertyType propertyTypeInfo in dmSolution.PropertyTypes)
//            {
//                _boPersistor.AddBusinessObject(propertyTypeInfo);
//            } 
//            foreach (UIControlType controlTypeInfo in dmSolution.UIControlTypes)
//            {
//                _boPersistor.AddBusinessObject(controlTypeInfo);
//            }
//            foreach (UIControlMapperType controlMapperTypeInfo in dmSolution.UIControlMapperTypes)
//            {
//                _boPersistor.AddBusinessObject(controlMapperTypeInfo);
//            }
//            foreach (UIGridColumnControlType gridColumnControlTypeInfo in dmSolution.UIGridColumnControlTypes)
//            {
//                _boPersistor.AddBusinessObject(gridColumnControlTypeInfo);
//            }
//
//            foreach (DMClass dmClass in dmSolution.AllClasses)
//            {
//                _boPersistor.AddBusinessObject(dmClass);
//                foreach (DMProperty property in dmClass.Properties)
//                {
//                    _boPersistor.AddBusinessObject(property);
//                    foreach (DMPropRule propRuleInfo in property.PropRules)
//                    {
//                        _boPersistor.AddBusinessObject(propRuleInfo);
//                    }
//                    DMLookupList dmLookupList = property.LookupList;
//                    if (dmLookupList != null)
//                    {
//                        _boPersistor.AddBusinessObject(dmLookupList);
//                        AddRelatedChildren(dmLookupList);
//                    }
//                }
//                DMObjectIdentity primaryKey = dmClass.ObjectIdentity;
//                if (primaryKey != null)
//                {
//                    _boPersistor.AddBusinessObject(primaryKey);
//                }
//                foreach (DMUniqueConstraint uniqueConstraint in dmClass.UniqueConstraints)
//                {
//                    _boPersistor.AddBusinessObject(uniqueConstraint);
//                    foreach (DMUniqueConstraintProperty uniqueConstraintProperty in uniqueConstraint.UniqueConstraintProperties)
//                    {
//                        _boPersistor.AddBusinessObject(uniqueConstraintProperty);
//                    }
//                }
//                foreach (DMRelationship relationship in dmClass.OwnerRelationships)
//                {
//                    _boPersistor.AddBusinessObject(relationship);
//                    foreach (DMRelationshipProperty relatedPropertyInfo in relationship.RelationshipProperties)
//                    {
//                        _boPersistor.AddBusinessObject(relatedPropertyInfo);
//                    }
//                }
//                foreach (UIView uiView in dmClass.UIViews)
//                {
//                    _boPersistor.AddBusinessObject(uiView);
//                    AddUIGridInfo(uiView);
//                    AddUIFormInfo(uiView);
//                } 
//            }
//        }
//
//        private void AddUIGridInfo(UIView uiView)
//        {
//            UIGridInfo uiGrid = uiView.UIGridInfo;
//            if (uiGrid != null)
//            {
//                _boPersistor.AddBusinessObject(uiGrid);
//                foreach (UIGridColumnInfo uiColumnInfo in  uiGrid.UIColumns)
//                {
//                    _boPersistor.AddBusinessObject(uiColumnInfo);
//                }
//            }
//        }
//
//        private void AddUIFormInfo(UIView uiView)
//        {
//            UIFormInfo uiForm = uiView.UIFormInfo;
//            if (uiForm != null)
//            {
//                _boPersistor.AddBusinessObject(uiForm);
//                foreach (UITab uiTabInfo in  uiForm.UITabs)
//                {
//                    _boPersistor.AddBusinessObject(uiTabInfo);
//                    foreach (UIColumnLayout uiColumnLayoutInfo in  uiTabInfo.UIColumnLayouts)
//                    {
//                        _boPersistor.AddBusinessObject(uiColumnLayoutInfo);
//                        foreach (UIField uiFieldInfo in  uiColumnLayoutInfo.UIFields)
//                        {
//                            _boPersistor.AddBusinessObject(uiFieldInfo);
//                        }
//
//                    }
//                }
//            }
//        }
//
//        private void AddRelatedChildren(IBusinessObject businessObject)
//        {
//            foreach (IRelationship relationship in businessObject.Relationships)
//            {
//                if (relationship is IMultipleRelationship)
//                {
//                    IMultipleRelationship multipleRelationship = (IMultipleRelationship) relationship;
//                    foreach (BusinessObject bo in multipleRelationship.BusinessObjectCollection)
//                    {
//                        _boPersistor.AddBusinessObject(bo);
//                    }
//                }
//            }
//        }
//
//        public IBoPersistor BoPersistor
//        {
//            get { return _boPersistor; }
//        }
//
//        public void Persist()
//        {
//            _boPersistor.Persist();
//        }
//    }
}
